<?php

namespace Yi\Permission\Support;

use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Log;

class RedisService
{
    static function geoAdd($data = ['longitude' => '', 'latitude' => ''], $id, $key = "key", $flag = "")
    {
        if ($data['longitude'] && $data['latitude'] && $id) {
            $idFlag = $flag ? ($flag . ":" . $id) : $id;
            return Redis::geoAdd($key, $data['longitude'], $data['latitude'], $idFlag);
        } else {
            return false;
        }
    }


    // $lists = Redis::geoRadius(
    //     'community_addr',
    //     '116.319835',
    //     '40.028771',
    //     5,
    //     'km',
    //     $options
    // );
    static function geoRadiusList($key = "key", $longitude = "", $latitude = "", $dist = 1, $unit = "km", $options = ['WITHDIST'])
    {

        $lists = Redis::geoRadius(
            $key,
            $longitude,
            $latitude,
            $dist,
            $unit,
            $options
        );

        return $lists;
    }


    /**
     * 返回总条数
     * 
     */
    static function getZardTotal($key)
    {
        $count = Redis::zcard($key);
        Log::info("setgetZardTotal key {$key} : $count\n");
    }
}
